var Relation = require('../relation');
var User = require('../user')
var Card = require('../card')
var Activity = require('../activity');
var initRedisCache = require('../../lib/InitRedisCache');
var Faction = require('../faction');
var fmproxy = require('../factionmember');
var Creditspolicy = require('../creditspolicy');
var FactionMember = require('../../entity').FactionMember;
var activity = require('../../entity').Activity;
var UserE = require('../../entity').User;



function test(){
    Card.findCardById('5437dcb5beeb1c0336cbd887', function(err, card){
        UserE.find({_id: '5437b2a86f03d9591e7246b5'}).exec(function(err, user){
            UserE.update({_id: user._id}, {$set: {card: card._id}}, {}, function(err, data){
               console.log(data)
            });
        })
    })
   /* UserE.find({_id: '5437b2a86f03d9591e7246b5'}).exec(function(err, user){
        Card.newAndSave(user, {}, function(err, card){
            console.log(card)
        })
    })*/
    /*Faction.findById('54102f517c99781e517c7d96', function(err, faction){
        User.getUserById('5437b2a86f03d9591e7246b5', function(err, user){
            var card = {
                 company :"",
                position: "",
                business: "",
                product: ""
            }
            fmproxy.newAndSave(faction, user, card, function(err, fm){
                console.log(fm);
            });
        })
    });*/
    /*Activity.getAllMyActs('53fdccc2f371cd1b755c0d8c', function(err, acts){
        if(err) return console.log(err.message);
        console.log(acts);
        process.exit();
    })*/
    /*var m1 = {
        id: '540443195c067a5b6f57f04a',
        name: '陈国明',
        gender: 'male',
        company: '大星海国际贸易',
        position: '少将',
        business: '武器出口',
        product: '导弹 软件'
    }
    var m2 = {
        id: '53fdccc2f371cd1b755c0d8c',
        name: '刘国尧',
        gender: 'male',
        company: '中科方的软件',
        position: '程序员',
        business: 'IT',
        product: '软件'
    }
    var m3 = {
        id: '53f1bfb4b6c264784b52db.7c1b',
        name: '校长',
        gender: 'female',
        company: '中科软件',
        position: '程序员',
        business: 'IT',
        product: '硬件 软件'
    }
    var key = /软/;
    FactionMember.find({$or: [
        {'member.name': key},
        {'member.gender': key},
        {'member.position': key},
        {'member.company': key},
        {'member.business': key},
        {'member.product': key}
    ]}).exec(function(err, fms){
        if(err) return console.log(err.message);
        console.log(fms);
        process.exit();
    })*/
    /*var fm1 = new FactionMember();
    fm1.faction = '54092b2d0588b0ec0e888982';
    fm1.member = m3;
    fm1.save(function(err, fm){
        if(err) return console.log(err.message);
        console.log(fm);
        process.exit();
    })*/
    /*Creditspolicy.newAndSave({name: '策略'}, function(err, csp){
        if(err) return console.log(err.message);
        console.log(csp);
        process.exit();
    })*/
    //540443195c067a5b6f57f04a
    /*Creditspolicy.findById('540443195c067a5b6f57f04a', function(err, csp){
        var credit = csp;
        User.getUserById('53fdccc2f371cd1b755c0d8c', function(err, user){
            Faction.newAndSave(user, '测试帮派', '没有', credit, function(err, faction){
                if(err) return console.log(err.message);
                console.log(faction);
                process.exit();
            })
        })
    })*/
    /*Faction.findById('54044496e97137986f0b1044', function(err, faction){
        console.log(faction);
        process.exit();
    })*/
    /*Faction.findByCreator({id: '53fdccc2f371cd1b755c0d8c'}, function(err, faction){
        console.log(faction);
        process.exit();
    })*/
    /*Faction.findByContainsUser({id: '53f1bfb4b6c264784b527c1b'}, function(err, factions){
        if(err) console.log(err.message);
        console.log(factions[0]._id.toString());
        process.exit()
    })*/
    /*Activity.cancelAttend('53f1c5bbd700cf9c4c78506a', {id:'53f1bff4566d5e954bd3571b'}, function(err, data){
        if(err) console.log(err.message);
        console.log(data);
        process.exit()
    })*/
    /*Activity.addAtend('53f2f5948274b6216f9aa720', {id:'53f1bff4566d5e954bd3571b',
    name:'教父', gender:'male', time:new Date()}, function(err, data){
        if(err) console.log(err.message);
        console.log(data);
        process.exit()
    })*/
    /*Activity.find({attends: {$elemMatch:{id:'53f1bff4566d5e954bd3571b'}}}).sort({startTime:1}).exec(function(err, data){
        if(err) console.log(err.message);
        console.log(data);
        process.exit()
    })*/
    /*Activity.pageMyActlist('53f2f2b6b9149b536e307a8e', 1, 10, function(err, data){
        if(err) console.log(err.message);
        console.log(data);
        process.exit()
    })*/
    /*User.getAllUsers(function(err, users){
        if(err) console.log(err.message);
        for(var i in users){
            console.log(users[i].name)
        }
        process.exit()
    })*/
    //initRedisCache.initUserCache();
}

test();